#ifndef ADJACENCYLIST_H
#define ADJACENCYLIST_H

#include <vector>
#include <iostream>
#include "Edge.h"

namespace zbp
{
	using namespace std;

	class AdjacencyList
	{
	public:
		AdjacencyList() { };

		AdjacencyList(int nodes_count)
		{
			for(int i = 0; i < nodes_count; i++)
			{
				_data.push_back(std::vector<Edge>());
			}
		}
  
		inline std::vector<Edge> & operator[] (int i) 
		{  
			return _data[i]; 
		}

		inline const std::vector<Edge> & operator[] (int i) const 
		{ 
			return _data[i]; 
		}

		vector<Edge> get_edges_for_node(int index)
		{
			if (get_nodes_count() > index)
			{
				return _data[index];
			}
		
			std::vector<Edge> empty;

			return empty;
		}

		int get_nodes_count()
		{
			return _data.size();
		}

		void set_nodes_count(int count)
		{
			while(_data.size() < count)
			{
				_data.push_back(std::vector<Edge>());
			}
		}

		void remove_last_node()
		{
			_data.erase(_data.end() - 1);
		}

		void push_back_edge(Edge e)
		{
			int node_index = e.coord.first;

			set_nodes_count(node_index + 1);

			_data[node_index].push_back(e);		
		}

		void display(std::ostream &output = cout)
		{
			AdjacencyList d = *this;

			output << endl;
			for (int i = 0; i < d._data.size(); i++)
			{
				for (int j = 0; j < d[i].size(); j++)
				{
					output << "E(" << d[i][j].coord.first << " ," << d[i][j].coord.second << ") = " << d[i][j].weight << ";  ";
				}

				output << endl;
			}
		}

	private:
		std::vector<std::vector<Edge>> _data;  
	};
}

#endif